/*
 Simple Integer Analysis
 Author: Danny Beaumont
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
define our class below
*/
public class Simple_Integer_Analyzer extends Frame
{
	private Simple_Integer_Analyzer()
	{
		// our default constructor
		/*
		 * The following components exist by default
		 */
		Frame win = new Frame("Simple Number Analyzer");
		JButton button1 = new JButton("Analyze");
		final JTextField input = new JTextField(5);
		final JTextArea output = new JTextArea(20,15);
		Label tag = new Label("Number: ");
		win.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});
		button1.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e)
			{
				//add actions here
				//System.exit(0);
				String in = input.getText();
				try{new java.math.BigInteger(in);
				//output.append("Is Valid number");}
				if(prime(Integer.parseInt(in))){
					output.append("Prime\n");
				}else if(!prime(Integer.parseInt(in))){
					output.append("not Prime\n");
					
				}
				
				}
				catch(NumberFormatException ex){
					output.append("Invalid input");
				}
				//output.append(in+"\n");
			}
			
		});
		win.add(tag);
		win.add(input);
		win.add(button1);
		win.add(output);
		win.setSize(250,275);
		win.setLayout(new FlowLayout(FlowLayout.LEFT));
		win.setVisible(true);
		
	}
	public static void main(String[] argv)
	{
		//add outputs here	
		Runnable r = new Runnable()
		{
			public void run()
			{
				new Simple_Integer_Analyzer();
			}
		};
		EventQueue.invokeLater(r);
	}
	private static boolean prime(int number){
	
		boolean isPrime = true;
		if(number%2 == 0){
			if(number == 2){
				isPrime = true;
			}else{
				isPrime = false;
			}
			
			
			}
		else if(number%2 != 0){
			
		int count =3;
		do{
			if(number%count == 0){
				isPrime = false;
			}
			count = count+2;
			
		}
		while(count < number);
		}
		return isPrime;
	}
	

}